<template>
  <a-modal
    title="未完成的学校"
    :width="820"
    :visible="visible"
    :confirmLoading="loadings"
    @ok="() => { $emit('ok') }"
    @cancel="() => { $emit('cancel') }"
    footer
  >
    <a-spin :spinning="loadings">
        <div class="table-page-search-wrapper">
          <a-form layout="inline">
        </a-form>
        </div>

      <a-table :columns="columns" :dataSource="loadData" :rowKey="(record,index)=>{return index}" :pagination="pagination" @change="TableChange">
          <a slot="name" slot-scope="text">{{ text }}</a>
                  <span slot="action" slot-scope="text, record">
          <template>
            <a @click="handleJump(record)">查看</a>
          </template>
        </span>
        </a-table>
    </a-spin>
    <!-- <a-form>{{loadData[0].nickname}}</a-form> -->
  </a-modal>
</template>
<script>
import { GetSchoolUser } from '../../../../api/school'

const columns = [
  {
    title: '学校名称',
    dataIndex: 'name',
  },
  {
    title: '联系人',
    dataIndex: 'contract'
  },
  {
    title: '电话',
    dataIndex: 'phone',
  },
  {
    title: '区',
    dataIndex: 'area',
  },
  {
    title: '详细地址',
    dataIndex: 'address',
  },
  {
    title: '任务状态',
    dataIndex: 'statusname'
  }
]
// 表单字段
const fields = ['id']
const loadData = []
export default {
  props: {
    visible: {
      type: Boolean,
      required: true
    },
    loading: {
      type: Boolean,
      default: () => false
    },
    model: {
      type: Object,
      default: () => null
    }
  },
  data () {
    this.columns = columns
    this.loadData = loadData
    this.formLayout = {
      labelCol: {
        xs: { span: 24 },
        sm: { span: 7 }
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 13 }
      }
    }
    return {
      loadings: this.loading,
      pagination:{
        defaultPageSize:5,
        showTotal: total => `共 ${total} 条数据`,
        showSizeChanger:false,
        pageSizeOptions: ['5', '10', '15', '20'],
        onShowSizeChange:(current, pageSize)=>this.pageSize = pageSize
        },
      form: this.$form.createForm(this),
      loadData: loadData,
      id: 0,
      froms: {},
      schoolId: 0
      // ids:0,
    }
  },
  created () {
    // 防止表单未注册
    // fields.forEach(v => this.form.getFieldDecorator(v))
    this.$watch('model', () => {
      this.id = this.model.id
      this.getSchool(this.id)
      // this.model && this.form.setFieldsValue(pick(this.model, fields))
    })
  },
  methods: {
    // 调用接口获取数据
    async getSchool(id) {
      const result = await GetSchoolUser({task_id: id, status: 1})
      console.log(result)
      if(result.data.length > 0) {
        this.loadData = result.data
      } else {
        this.loadData = []
      }
    },
    TableChange() {}
  }
}
</script>
